<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>闲言轻博客</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
    {{template "/comn/link.html"}}
</head>
<body class="lay-blog">
    {{template "/comn/header.html" .}}
		<div class="container-wrap">
			<div class="container">
					<div class="contar-wrap">
						{{if .islogin}}
							<h4 class="item-title">
								<p>
									<i class="layui-icon layui-icon-speaker"></i>公告：
									<span>欢迎来到{{.User.Name}}的轻博客</span>
									<span>你是否要 <a href="/logout">登出</a></span>
								</p>
							</h4>
						{{if compare .User.Role 0}}
							<h4 class="item-title">
								<p>
									<a href="/note/new">
										<i class="layui-icon layui-icon-add-1">&#xe654;</i>
										<span>新增文章</span>
									</a>
								</p>
							</h4>
						{{end}}
						{{else}}
							<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
								<div class="layui-form-item">
									<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
									<input type="text" name="email" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
								</div>
								<div class="layui-form-item">
									<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
									<input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
								</div>
								<div class="layui-form-item">
									<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
									<button class="layui-btn layui-btn-primary" onclick="window.location.href='/reg'" >注册</button>
								</div>
							</div>
						{{end}}
					</div>
			</div>
		</div>
		{{template "comn/footer.html"}}
	<script>
		layui.use(['form', 'jquery'], function(){
			var $ = layui.$
					,form = layui.form
					,router = layui.router();

			form.render();

			//提交
			form.on('submit(LAY-user-login-submit)', function(obj){

				$.post("/login",obj.field,function (data) {
					if(data.code==0){
						layer.msg('登录成功');
						if(data.action){
							setTimeout(function () {
								window.location.href=data.action
							},300)
						}
					}else{
						layer.msg('登录失败');
					}
				},"json").error(function () {
					layer.msg('网络延迟');
				})


			});


		});
	</script>
</body>
</html>